/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-12-3
 * @Time  : 下午3:31
 * @brief :
 */
(function () {
    var Dialog = require('common:widget/ui/dialog/dialog.js').Dialog,
        $page = $('.page-redeemdemand'),
        dialog = new Dialog();

    $page.find('.btn-redeem').click(function(){
        if($(this).hasClass('btn-main')){
            var amount = $.trim($page.find('.amount').val());
            $page.find('.error-tip').hide();
            if(parseFloat(amount)<=0 || !/^\d+(\.\d+)?$/.test(amount)){
                dialog.show('赎回金额填写错误');
            }else if(parseFloat(amount)> P.data('available_amount')){
                dialog.show('超过可赎回份额');
            }else{
                $(this).addClass('btn-disable').removeClass('btn-main');
                $.post('/user/redeeming',{
                    'pid':1,
                    'amount':amount
                },function(ret,status){
                    location.href="/user/redeemingpage?pid=1&trade_id="+ret.data;
                },'json');
            }
        }

    });
})();